<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        async function getData(){
           const user = await new Promise((resolve,reject)=>{
                console.log('请求姓名')
                try{
                    setTimeout(()=>{
                        console.log('请求姓名成功')
                        const user ={
                            username:'高雅琳'
                        }
                        resolve(user)
                    },2000)

                }catch(e){
                    reject(e.message)
                }
           })

           const age =await new Promise((resolve,reject)=>{
                    console.log('请求年龄')
                    try{
                        setTimeout(()=>{
                            console.log('请求年龄成功')
                            const age ={
                                age:22
                            }
                            resolve({...user,...age})
                        },2000)
                    }catch(e){
                        reject(e.message) 
                        }

           })

           const sex = await new Promise((resolve,reject)=>{
                    console.log('请求性别')
                    try{
                        setTimeout(()=>{
                            console.log('请求性别成功')
                            const sex ={
                                sex:'女'
                            }
                            resolve({...age,...sex})
                        },2000)
                    }catch(e){
                        reject(e.message)
                    }
           })
            //最后异步的操作 我们可以不用await 也会最后执行
           console.log('user',sex) 
        }
        getData()
        

    </script>
</body>
</html>